﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DbLibrary;
using DbLibrary.Helpers;
using DbLibrary.Models;

namespace MVC_web_Face.Controllers
{
    public class FillupCreateWrap
    {
        public bool CreatePeriod { get; set; }
        public string PeriodName { get; set; }
        public string PeriodComments { get; set; }
        public bool? PeriodTest { get; set; }

        public bool CreateCar { get; set; }
        public string CarName { get; set; }
        public bool? CarTest { get; set; }
        
        public Int32 CarId { get; set; }
        public Int32 ReportPeriodId { get; set; }
        public DateTime Date { get; set; }
        public Int32 Kilometers { get; set; }
        public double Liters { get; set; }
        public decimal Price { get; set; }

        public FillupData GetFillupData()
        {
            if (CreatePeriod)
            {
                var p = new ReportPeriod
                {
                    Comments = PeriodComments,
                    Name = PeriodName,
                    Test = PeriodTest.HasValue && PeriodTest.Value
                };
                ReportPeriodId = ReportPeriodCreateHelper.Instance.CreatePeriod(p);
            }
            if (CreateCar)
            {
                var c = new Car
                {
                    Name = CarName,
                    Test = CarTest.HasValue && CarTest.Value
                };
                CarId = CarCreateHelper.Instance.CreateCar(c);
            }

            return new FillupData
            {
                ReportPeriodId = ReportPeriodId,
                CarId = CarId,
                Date = Date,
                Kilometers = Kilometers,
                Liters = Liters,
                Price = Price
            };
        }
    }
}